﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.t303Menu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void t303_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            t303Mgr mgr = new t303Mgr();
            e.Total = int.Parse(mgr.GetRecordCount_t303(e.Parameters[t303_Filter.ParamPrefix]));
            IList<t303> list = mgr.FindAllByPage_t303(e.Start.ToString(), e.Limit.ToString(), e.Parameters[t303_Filter.ParamPrefix]);
            t303_MainStore.DataSource = list;
            t303_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            t303Mgr mgr = new t303Mgr();
            RowSelectionModel sm = t303_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                t303 _t303 = new t303();
                _t303.t303_01 = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_t303(_t303))
                {
                    log.Debug("t303中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            t303_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            t303Mgr mgr = new t303Mgr();
            t303 _t303 = new t303();
            if (Hid.Text.Length > 0)
                _t303 = mgr.FindById_t303(int.Parse(Hid.Text));
            
			_t303.t303_02 = Txtt303_02.Text.Trim();
			_t303.t303_03 = Txtt303_03.Text.Trim();
			_t303.t303_04 = Txtt303_04.Text.Trim();
			_t303.t303_05 = Txtt303_05.Text.Trim();
			_t303.t303_06 = Txtt303_06.Text.Trim();
			_t303.t303_07 = Txtt303_07.Text.Trim();
			_t303.t303_08 = Txtt303_08.Text.Trim();
			_t303.t303_09 = Txtt303_09.Text.Trim();
			_t303.t303_10 = Txtt303_10.Text.Trim();
			_t303.t303_11 = Txtt303_11.Text.Trim();
			_t303.t303_12 = Txtt303_12.Text.Trim();
			_t303.t303_13 = Txtt303_13.Text.Trim();
			_t303.t303_14 = Txtt303_14.Text.Trim();
			_t303.t303_15 = Txtt303_15.Text.Trim();
			_t303.t303_16 = Txtt303_16.Text.Trim();
			_t303.t303_17 = Txtt303_17.Text.Trim();
			_t303.t303_18 = Txtt303_18.Text.Trim();
			_t303.t303_19 = Txtt303_19.Text.Trim();
			_t303.t303_20 = Txtt303_20.Text.Trim();
			_t303.t303_21 = Txtt303_21.Text.Trim();
			_t303.t303_22 = Txtt303_22.Text.Trim();
			_t303.t303_23 = Txtt303_23.Text.Trim();
			_t303.t303_24 = Txtt303_24.Text.Trim();
			_t303.t303_25 = Txtt303_25.Text.Trim();
			_t303.t303_70 = Txtt303_70.Text.Trim();
			_t303.t303_71 = Txtt303_71.Text.Trim();
			_t303.collection_time = Txtcollection_time.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_t303(_t303);
            else
                isok = mgr.Add_t303(_t303);
            if (isok)
            {
                t303_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("t303中执行了保存（插入或修改），并成功");
                t303_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}